What does `__import__('pkg_resources').declare_namespace(__name__)` do?

It boils down to two things: import is a Python statement that will import a package using a string as the name of the package. It returns a new object that represents the imported package. So foo = __import__('bar') will import a package named bar and store a reference to its objects in a local object variable foo From PEP 382 declare_namespace() is a mechanism for splitting a single Python package across multiple directories on disk So import__('pkg_resources').

Declare_namespace(__name__) will import all of the symbols from the 'pkg_resources' package and then add them to a namespace whose name is stored in name If this code were in my_namespace/__init__. Py then name is my_namespace and the symbols in pkg_resources are being added to a namespace package named my_namespace import is used rather than import so that there is no extra symbol left over named pkg_resources See this question for discussion on the older mechanism for achieving the same effect.

It boils down to two things: __import__ is a Python statement that will import a package using a string as the name of the package. It returns a new object that represents the imported package. So foo = __import__('bar') will import a package named bar and store a reference to its objects in a local object variable foo.

From PEP 382, declare_namespace() "is a mechanism for splitting a single Python package across multiple directories on disk. " So __import__('pkg_resources'). Declare_namespace(__name__) will import all of the symbols from the 'pkg_resources' package and then add them to a namespace whose name is stored in __name__.

If this code were in my_namespace/__init__. Py, then __name__ is my_namespace and the symbols in pkg_resources are being added to a namespace package named my_namespace. __import__ is used rather than import so that there is no extra symbol left over named pkg_resources.

See this question for discussion on the older mechanism for achieving the same effect.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions